package com.dmtt.web.common;

import com.dmtt.util.ExcelUtil;
import com.dmtt.web.entity.*;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.xml.crypto.Data;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;


@Service
public class ExportServiceImpl {

    public ResponseEntity<byte[]> buildResponseEntity(InputStream is, String name) throws Exception {
        HttpHeaders header = new HttpHeaders();
        String fileSuffix = name.substring(name.lastIndexOf('.') + 1);
        fileSuffix = fileSuffix.toLowerCase();
        Map<String, String> arguments = new HashMap<String, String>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar=Calendar.getInstance();
        arguments.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        arguments.put("xls", "application/vnd.ms-excel");
        String contentType = arguments.get(fileSuffix);
        header.add("Content-Type", (StringUtils.hasText(contentType) ? contentType : "application/x-download"));
        header.add("Content-Length", String.valueOf(is.available()));
        header.add("Content-Disposition", URLEncoder.encode(formatter.format(calendar.getTime()), "UTF-8"));

        byte[] bs = IOUtils.toByteArray(is);
        return new ResponseEntity<>(bs, header, HttpStatus.OK);
    }

    public InputStream export(List list,List<String> strings,int flag) {
        ByteArrayOutputStream output = null;
        InputStream inputStream1 = null;
        SXSSFWorkbook wb = new SXSSFWorkbook(1000);// 保留1000条数据在内存中
        SXSSFSheet sheet = wb.createSheet();
//        String[] a = new String[]{"月份","稼动率","不稼动率","时间"};
        // 设置报表头样式
        CellStyle header = ExcelUtil.headSytle(wb);// cell样式
        CellStyle content = ExcelUtil.contentStyle(wb);// 报表体样式
        if (list != null && list.size() > 0) {
            if (flag == 1) {
                for (int i = 0; i < list.size(); i++) {
                    MovemontRate movemontRate = (MovemontRate) list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getGrain());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getNonGrain());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            } else if (flag == 2) {
                for (int i = 0; i < list.size(); i++) {
                    MovemontRate movemontRate = (MovemontRate) list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getGrain());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getNonGrain());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(movemontRate.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==3){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA0());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {  5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==4){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA0());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {  5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            } else if (flag==5){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==6){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag == 8) {
                for (int i = 0; i < list.size(); i++) {
                    ChangeGrain changeGrain = (ChangeGrain) list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    String months = changeGrain.getMonths();
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getCountTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getTarget());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag == 7) {
                for (int i = 0; i < list.size(); i++) {
                    ChangeGrain changeGrain = (ChangeGrain) list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getCountTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getTarget());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(changeGrain.getTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] { 5000, 5000, 5000, 5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            } else if (flag==9){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getNonTarget());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000,  5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==10){
                for (int i = 0; i < list.size(); i++) {
                    Activation activa = (Activation)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getTotal());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getNonTarget());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000,  5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,5000, 5000, 5000 };
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==11){
                for (int i = 0; i < list.size(); i++) {
                    CarStatus activa = (CarStatus)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    if (null != activa.getGroupId()) {
                        cell.setCellValue(activa.getGroupId());
                    }else {
                        cell.setCellValue("");
                    }
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getJobName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvStatus());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getErrStatus());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    if (null != activa.getElectric()) {
                        cell.setCellValue(activa.getElectric());
                    }else{
                        cell.setCellValue("");
                    }
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000,  5000, 5000, 5000, 5000, 5000};
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==12){

                int a = 1;
                for (int i = 0; i < list.size(); i++) {
                    AgcStatistics activa = (AgcStatistics)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(a++);
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getJobId());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getStatus());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getStartTime());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getEndTime());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getAllTime());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getPoint());
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000,  5000, 5000, 5000, 8000, 8000, 5000, 5000};
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==13){

                int a = 1;
                for (int i = 0; i < list.size(); i++) {
                    AgcAverage activa = (AgcAverage)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(a++);
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getAgvName());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getMovement()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA2()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA3()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA4()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA8()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getImmobility()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA5()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA6()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA7()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28()+"%");
                    cell.setCellStyle(content);
//                    System.out.println(activa.getImmobility());
//                    System.out.println(activa.getMovement());
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,
                            5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000,5000,5000};
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }else if (flag==14){

                int a = 1;
                for (int i = 0; i < list.size(); i++) {
                    AgcAverage activa = (AgcAverage)list.get(i);
                    SXSSFRow row = sheet.createRow(i + 1);
                    int j = 0;
                    SXSSFCell cell = row.createCell(j++);
                    cell.setCellValue(a++);
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getMonths());
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getMovement()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA1()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA2()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA3()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA4()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA8()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getImmobility()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA5()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA6()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA7()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA9()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA10()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA11()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA12()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA13()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA14()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA15()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA16()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA17()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA18()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA19()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA20()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA21()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA22()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA23()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA24()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA25()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA26()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA27()+"%");
                    cell.setCellStyle(content);
                    cell = row.createCell(j++);
                    cell.setCellValue(activa.getA28()+"%");
                    cell.setCellStyle(content);
                    // 字段名所在表格的宽度
                    int[] ints = new int[] {5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,
                            5000, 5000, 5000, 5000, 5000,5000, 5000, 5000, 5000, 5000,5000,5000};
                    // 设置表头样式
                    ExcelUtil.initTitleEX(sheet, header, strings, ints);
                }
            }

        }

        try {
            output = new ByteArrayOutputStream();
            wb.write(output);
            inputStream1 = new ByteArrayInputStream(output.toByteArray());
            output.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (output != null) {
                    output.close();
                    if (inputStream1 != null)
                        inputStream1.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return inputStream1;
    }
}